home *** CD-ROM | disk | FTP | other *** search
/ Delphi Developer's Kit 1996 / Delphi Developer's Kit 1996.iso / power / timerit / timerit.pas < prev    next >
Pascal/Delphi Source File  |  1995-12-22  |  2KB  |  78 lines

  1. unit Timerit;
  2. {*******************************}
  3. { Author: Eric Uber             }
  4. { CIS Account: 71102,3034       }
  5. { Written: June 14th 1995.      }
  6. { Freeware, distribute at will. }
  7. {*******************************}
  8. interface
  9.  
  10. uses
  11.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  12.   Forms, Dialogs, Extctrls;
  13.  
  14. type
  15.   TNotifyTickEvent = procedure(sender: TObject; iCurrentTick: integer) of object;
  16.  
  17.   TTimerIterate = class(TTimer)
  18.   private
  19.     { Private declarations }
  20.     iCurrentTick: integer;
  21.     fNumTicks: integer;
  22.     fOnLastTick : TNotifyTickEvent;
  23.   protected
  24.     { Protected declarations }
  25.     procedure SetfNumTicks(iNumTicks: integer);
  26.     procedure Timer; override;
  27.   public
  28.     { Public declarations }
  29.  
  30.   published
  31.     { Published declarations }
  32.     property NumTicks   : integer read fNumTicks write SetfNumTicks;
  33.     property OnLastTick : TNotifyTickEvent read fOnLastTick write fOnLastTick;
  34.   end;
  35.  
  36. procedure Register;
  37.  
  38. implementation
  39.  
  40. {-----------------------------------------------}
  41. { Method:                                       }
  42. {-----------------------------------------------}
  43. procedure Register;
  44. begin
  45.   RegisterComponents('Custom', [TTimerIterate]);
  46. end;
  47.  
  48. {-----------------------------------------------}
  49. { Method:                                       }
  50. {-----------------------------------------------}
  51. procedure TTimerIterate.SetfNumTicks(iNumTicks: integer);
  52. begin
  53.   fNumTicks := iNumTicks;
  54.   iCurrentTick := fNumTicks;
  55. end;
  56.  
  57. procedure TTimerIterate.Timer;
  58. begin
  59.   if iCurrentTick = 0 then
  60.      begin
  61.        Enabled := False;
  62.        iCurrentTick := fNumTicks;
  63.      end
  64.    else
  65.      begin
  66.        inherited Timer;
  67.        Dec(iCurrentTick);
  68.        if ( iCurrentTick = 0 ) then
  69.          begin
  70.            if Assigned(fOnLastTick) then
  71.               fOnLastTick(self,(iCurrentTick+1));
  72.          end
  73.      end;
  74. end;
  75.  
  76.  
  77. end.
  78.